<?php
namespace V1;
class Config extends \ResourceClass {
  public $isActive = true;
  public $remark = '获取配置信息';

  public function post(array $req, array $post, &$result) {
    if (!isset($post['platform'])) {
      return 'require platform';
    }
    if (!isset($post['version'])) {
      return 'require version';
    }
    if (!isset($post['device'])) {
      return 'require device info';
    }
    if (!isset($post['uuid'])) {
      return 'require uuid';
    }

    $version = $post['version'];
    $platform = $post['platform'];
    $device = $post['device'];
    $uuid = $post['uuid'];
    $imei = isset($post['imei'])?$post['imei']:0;
    $userId = isset($post['userId'])?$post['userId']:0;
    $ip = $this->getRealIp();
    $push_message_handler = new \Biz\PushMessageHandler();
    $user_log_cls = new \Cls\PushMessage\UserLog();
    $user_log_cls->create($version, $platform, $device, $uuid, $imei, $userId, $ip);
    $push_message_handler->insert_user_log($user_log_cls);

    $result = array(
		'interface_version'=>'0.1',
		'version'=>'0.1',
		'debug'=>false,
		'error_report'=>false,
        'description'=>'鲜桥是企业智能交易平台的全国领先品牌，长期专注于企业渠道、客户订单管理服务。帮助企业快速构建专属的客户订货智能平台，开拓分销渠道，加速资金回笼，四通八达，让买卖更容易。',
        'about_us'=>array(
            '联系方式'=>
                array(
                    'QQ'=>'3527001076',
                    '邮箱'=>'contact@freshqiao.com',
                    '电话'=>'4000 285 927',
                ),
            ),
        'enterpise_description'=>array(
            array('type'=>'char','value'=>'xxx 介绍'),
            array('type'=>'image','value'=>'http://mat1.gtimg.com/news/FERD_proj/kuaibao160606/abimg.jpg',),
            array('type'=>'video','value'=>'ydhres.oss-cn-hangzhou.aliyuncs.com/video/ydh.mp4',),
        ),
	);
    return '';
  }

  private function getRealIp(){
    $ip=false;
    if(!empty($_SERVER["HTTP_CLIENT_IP"])){
      $ip = $_SERVER["HTTP_CLIENT_IP"];
    }
    if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
      $ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
      if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
      for ($i = 0; $i < count($ips); $i++) {
        if (!eregi ("^(10|172\.16|192\.168)\.", $ips[$i])) {
          $ip = $ips[$i];
          break;
        }
      }
    }
    return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
  }
}
?>
